#pragma once
#include "raw_json_message.h"
#include "map.h"
#include "driver.h"

class configuration
{
private:
	bool all_ready;
	struct _raw_config {
		String name;
		String device;
		String param[PARAM_SIZE];
	};
	using raw_config = _raw_config[];
private:
	int *gpios_used;
	map<String, driver> name_driver;
public:
	configuration(raw_json_message conf_str) {
		config(conf_str);
		all_ready = true;
	}

	~configuration() {}
	bool is_all_ready() {
		return all_ready;
	}
	bool is_valid_task(task t) {}
	driver get_driver(task t){}
private:
	void config(raw_json_message conf_json_message) {}
};

const uint8_t OUTPUT_PWM = 0x8;

class gpio :public driver {
private:
	uint8_t pin;
public:
	int* pins_used(String param[PARAM_SIZE]) {
		auto res = new int[1];
		res[0] = param[0].toInt();
		return res;
	}
	bool setup(String param[PARAM_SIZE]) {
		pin = uint8_t(param[0].toInt());
		auto direction = uint8_t(param[1].toInt());
		if (direction < 0)return true;
		switch (direction)
		{
		case INPUT:
			return true;
		case OUTPUT:
			auto value = uint8_t(param[2].toInt());
			digitalWrite(pin, value);
			return true;
		case OUTPUT_PWM:
			auto value = uint8_t(param[2].toInt());
			analogWrite(pin, value);
			return true;
		default:
			break;
		}
	}
};